/********************************************************
 *
 * FILE NAME:   signaldecimation.h
 *
 * DESCRIPTION:
 *  Decimation of signal by factor N
 *
 ********************************************************/

#ifndef DECIMATOR_H
#define DECIMATOR_H

/********************************************************/
/*              Includes                                */
/********************************************************/

#include "../signalprocessing.h"
#include "buffer.h"

#include <QObject>

class Decimator : public QObject
{
    Q_OBJECT

        protected:
            class DecimationOSignal : public OSignal
            {

            private:
                Decimator *contextPtr;

            public:
                /********************************************************
                 * Function Name    :   DecimationOSignal
                 *
                 * Description      :   Constructor
                 *
                 * Side effects     :
                 *
                 * Comment          :
                 *
                 * Parameters       :   SignalDecimation *contextPtr = pointer to context
                 *                      size_t historyLength = num of previous samples that would be accessible
                 *
                 * Returns      	:
                 *
                 * Reviewed by      :   draganmarjanovic10@gmail.com, v_duschan@hotmail.com
                 *
                 ********************************************************/
                DecimationOSignal(Decimator *contextPtr, size_t historyLength): OSignal(historyLength)
                {
                    this->contextPtr = contextPtr;
                }

            protected:
                /********************************************************
                 * Function Name    :   onBurstRequest
                 *
                 * Description      :   Called when new burst of samples requested
                 *
                 * Side effects     :
                 *
                 * Comment          :
                 *
                 * Parameters       :   size_t burstLength = burst length
                 *
                 * Returns      	:   true if burst of samples successfully processed, else false
                 *
                 * Reviewed by      :   draganmarjanovic10@gmail.com, v_duschan@hotmail.com
                 *
                 ********************************************************/
                bool onBurstRequest(size_t outBurstLength);
            };

    private:
        ISignal* input;
        OSignal* output;
        int __downFactor;
        size_t __maxBurstLength;

    public:
        Decimator(QObject *parent = 0);

        static void registerTypes(const char *uri);

        /********************************************************
         * Function Name    :   SignalDecimation
         *
         * Description      :   Constructor
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :
         *
         *
         * Returns      	:
         *
         * Reviewed by      :   draganmarjanovic10@gmail.com, v_duschan@hotmail.com
         *
         ********************************************************/
        Q_INVOKABLE bool init(int downFactor,int inBurstLength);

        /********************************************************
         * Function Name    :   getInputSignal
         *
         * Description      :   Getter for input signal
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :
         *
         * Returns      	:   pointer to the input signal
         *
         * Reviewed by      :   draganmarjanovic10@gmail.com, v_duschan@hotmail.com
         *
         ********************************************************/
        ISignal * getInputSignal();
        Q_INVOKABLE EXPORT_SIGNAL(input, ISignal)

        /********************************************************
         * Function Name    :   getOutputSignal
         *
         * Description      :   Getter for output signal
         *
         * Side effects     :
         *
         * Comment          :
         *
         * Parameters       :
         *
         * Returns      	:   pointer to the output signal
         *
         * Reviewed by      :   draganmarjanovic10@gmail.com, v_duschan@hotmail.com
         *
         ********************************************************/
        OSignal * getOutputSignal();
        Q_INVOKABLE EXPORT_SIGNAL(output, OSignal)

};

#endif /* DECIMATOR_H */
